package net.crowdloud.client.user;

import net.crowdloud.client.crowdLoud.ButtonUserCrowdLoud;
import net.crowdloud.client.problem.ButtonProblem;
import net.crowdloud.client.problem.ProblemList;
import net.crowdloud.client.solution.ButtonSolution;
import net.crowdloud.client.solution.SolutionList;
import net.crowdloud.shared.entities.User;
import net.crowdloud.shared.utilities.HomeIcon;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @Feature
 */
public class UserPage extends VerticalPanel {

	public UserPage(final User user, String group) {

		VerticalPanel vp = new VerticalPanel();
		vp.setSize("97%", "100%");

		vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

		HorizontalPanel hp = new HorizontalPanel();
		hp.setWidth("300px");
		hp.setSpacing(5);

		hp.add(new ButtonNewUser());

		hp.add(new ButtonListUsers(group));

		hp.add(new HomeIcon());
		vp.add(hp);

		vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

		VerticalPanel vp1 = new VerticalPanel();
		vp1.setSize("100%", "100%");
		vp1.setSpacing(10);

		vp1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		Anchor userName = new Anchor();
		userName.setHTML("<a href='#'><font size=4 color=red><b>"
				+ user.getName() + "</b></font></a>");
		userName.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				RootPanel.get().clear();
				RootPanel.get().add(new UserForm(user));
			}
		});
		vp1.add(userName);

		vp1.add(new ButtonUserCrowdLoud(user));

		HTML html = new HTML(
				"<br><br><br><b><font color='blue' size='3'>Solutions</font></b> ");
		vp1.add(html);

		vp1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		vp1.add(new ButtonSolution(user));

		vp1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vp1.add(new SolutionList(user, user.getUserSolutions()));

		vp.add(vp1);

		VerticalPanel vp2 = new VerticalPanel();
		vp2.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vp2.setSize("100%", "100%");
		vp2.setSpacing(10);

		HTML htmlProblem = new HTML(
				"<br><br><br><b><font color='blue' size='3'>Needs</font></b> ");
		vp2.add(htmlProblem);

		vp2.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		vp2.add(new ButtonProblem(user));

		vp2.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vp2.add(new ProblemList(user, user.getUserProblems()));

		vp.add(vp2);

		this.add(vp);

	}
}
